package org.nerve.kotlin

import java.util.*

/**
 * Created by zengxm on 2017/7/24.
 */

fun main(args: Array<String>) {
    println("Hello world, now is ${Date()}")
    for (i in 0..1){
        println("${1-i} \tseconds will exit...")
        Thread.sleep(1000)
    }

    val persons = listOf(
            Person("马云",40),
            Person("马化腾",40),
            Person("李宏毅",50),
            Person("小娜扎")
    )

    println("年纪最大的是："+persons.maxBy { it.age })
    println("年纪最小的是："+persons.minBy { it.age })

    println("姓马的人有："+persons.filter { it.name.startsWith("马") })

    persons.forEach { println("${it.name} \t今年${it.age}岁 \t成年：${it.isAdult}") }
}

/**
 *
 */
data class Person(var name:String="无名氏",var age:Int=0){

    /**
     * 发表语录
     */
    infix fun say(word:String?) = println("$name \t道 : \"$word\"")

    /**
     * 判断此人是否已经成年
     */
    val isAdult:Boolean
        get() = age>=18

}